package com.smyh.UIM;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.smyh.UIM.device.DeviceParam01Fm;
import com.smyh.UIM.device.DeviceParam02Fm;
import com.smyh.UIM.device.DeviceParam03Fm;
import com.smyh.UIM.device.DeviceParam04Fm;
import com.smyh.UIM.device.DeviceParam05Fm;
import com.smyh.UIM.device.DeviceParam06Fm;
import com.smyh.UIM.device.DeviceStateFragment;
import com.smyh.UIM.device.DeviceSyncOptionFm;
import com.smyh.UIM.device.DeviceUpdateFm;

/**
 * Created by 姜龙 on 2016/7/6.
 */
public class DeviceFragment extends Fragment {

    private View view;
    private FrameLayout footfm;

    //当前视图：碎片view
    static Fragment currentfm;
    //指示器下面：碎片view
    static Fragment deviceStateFm,deviceParam1Fm,deviceParam2Fm,deviceParam3Fm,deviceParam4Fm,
            deviceParam5Fm,deviceParam6Fm,deviceOperFm,deviceUpdateFm;
    static FragmentManager childFragmentManager;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.activity_device, container, false);
        childFragmentManager = getFragmentManager();
        footfm = (FrameLayout) view.findViewById(R.id.footfm);

        deviceStateFm = new DeviceStateFragment();
        deviceParam1Fm = new DeviceParam01Fm();
        deviceParam2Fm = new DeviceParam02Fm();
        deviceParam3Fm = new DeviceParam03Fm();
        deviceParam4Fm = new DeviceParam04Fm();
        deviceParam5Fm = new DeviceParam05Fm();
        deviceParam6Fm = new DeviceParam06Fm();
        deviceOperFm = new DeviceSyncOptionFm();
        deviceUpdateFm = new DeviceUpdateFm();

        currentfm = deviceStateFm;
        getChildFragmentManager().beginTransaction().add(R.id.footfm,deviceStateFm)
                .add(R.id.footfm,deviceParam1Fm).add(R.id.footfm,deviceParam2Fm)
                .add(R.id.footfm,deviceParam3Fm).add(R.id.footfm,deviceParam4Fm)
                .add(R.id.footfm,deviceParam5Fm).add(R.id.footfm,deviceParam6Fm)
                .add(R.id.footfm,deviceOperFm).add(R.id.footfm,deviceUpdateFm)
                .show(deviceStateFm).hide(deviceParam1Fm).hide(deviceParam2Fm).hide(deviceParam3Fm)
                .hide(deviceParam4Fm).hide(deviceParam5Fm).hide(deviceParam6Fm).
                hide(deviceOperFm).hide(deviceUpdateFm).commit();
        return view;
    }

    public static void hiddenAll(){
        childFragmentManager.beginTransaction().hide(deviceStateFm).hide(deviceParam1Fm).hide(deviceParam2Fm).hide(deviceParam3Fm)
                .hide(deviceParam4Fm).hide(deviceParam5Fm).hide(deviceParam6Fm).hide(deviceOperFm).hide(deviceUpdateFm).commit();
    }
    public static void showCurrentFM(){
        hiddenAll();
        childFragmentManager.beginTransaction().show(currentfm).commit();
    }

    public static void setCurrentfm(int position) {
        //主机菜单
        switch (position){
            case 0:
                if(currentfm != deviceStateFm){
                    currentfm = deviceStateFm;
                    showCurrentFM();
                }
                break;
            case 1:
                if(currentfm != deviceParam1Fm){
                    currentfm = deviceParam1Fm;
                    showCurrentFM();
                }
                break;
            case 2:
                if(currentfm != deviceParam2Fm){
                    currentfm = deviceParam2Fm;
                    showCurrentFM();
                }
                break;
            case 3 :
                if(currentfm != deviceParam3Fm){
                    currentfm = deviceParam3Fm;
                    showCurrentFM();
                }
                break;
            case 4:
                if(currentfm != deviceParam4Fm){
                    currentfm = deviceParam4Fm;
                    showCurrentFM();
                }
                break;
            case 5:
                if(currentfm != deviceParam5Fm){
                    currentfm = deviceParam5Fm;
                    showCurrentFM();
                }
                break;
            case 6:
                if(currentfm != deviceParam6Fm){
                    currentfm = deviceParam6Fm;
                    showCurrentFM();
                }
                break;
            case 7:
                if(currentfm != deviceOperFm){
                    currentfm = deviceOperFm;
                    showCurrentFM();
                }
                break;
            case 8:
                if(currentfm != deviceUpdateFm){
                    currentfm = deviceUpdateFm;
                    showCurrentFM();
                }
                break;
        }

    }

}
